(function($){
	// 构造器
	$.fn.abdiChoice = function(){
		$.fn.abdiChoice.prototype = $.fn.abdiChoice.__proto__ = $.fn.abdiChoice.superO = $.fn.abdiComponent;
		return $.fn.abdiChoice;
	};
	 
	// 默认值
	$.fn.abdiChoice.defaults = {
		
	};
	
	// 初始化
	$.fn.abdiChoice.init = function(question){
		this.superO.init(question);
		this.data = $.extend({},this.defaults,question);
	};
	
	// 显示
	$.fn.abdiChoice.show = function(question){
		var component = this.superO; // 父类 
		var container = component.show(); // 父类内容
		var data = this.data;
		return container.append(getContentInfo(component,data));
	};
	
	// 根据实际情况处理所有Choice情况
	function getContentInfo(component,data){
		var answers = data.answers;
		var content = getEmptyDiv('question-choice');
		// 通过判断问题格式，添加样式
		var ul = $('<ul />');
		content.addClass('oneColumns').append(ul);
		$(answers).each(function(i,answer){
			var li = $('<li />');
			var answerContainer = getEmptyDiv('q-choice-piccheck');
			var choiceBtn = getEmptyDiv('q_choice_in fl').append(getBtnContent(data,answer));
			var answerContent = getEmptyDiv('q-choice-picchecktext fl').append(
						($('<p class="lineheight16"/>').append($('<em class="mr5">'+ answer.name +'</em>')))
					);
			ul.append(li.append(answerContainer.append(choiceBtn).append(answerContent)));
		});
		return content;
	};
	
	// 根据题型判断当前按钮的具体类型
	function getBtnContent(data,answer){
		if(data.type == '1'){
			return $('<input id="'+ answer.answeruuid +'" type="radio" name="'+ data.sortindex +'" value="'+ answer.answeruuid +'"></input>');
		}else if(data.type == '2'){
			return $('<input id="'+ answer.answeruuid +'" type="checkbox" name="'+ data.sortindex +'" value="'+ answer.answeruuid +'"></input>');
		}
	};
	
	// 填写答案
	$.fn.abdiChoice.fillAnswer = function(){
		var component = this.superO; // 父类 
		component.fillAnswer();

		var data = this.data;
		var results = data.results;
		
		$(results).each(function(i,result){
			//alert(result.resultuuid);
			$('#' + result.answeruuid).attr('checked',true);
		});
	};
})(jQuery);